package com.example.calculator;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;

public class CustomMenu extends Activity implements OnTouchListener {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.custom_menu);
		setViews();
	}

	@Override
	public boolean onKeyUp(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_MENU) {
			Intent returnIntent = new Intent();
			setResult(RESULT_CANCELED, returnIntent);
			finish();
			return true;
		}
		return super.onKeyUp(keyCode, event);
	}

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		int eventAction = event.getAction();

		Intent returnIntent = new Intent();

		if (eventAction == MotionEvent.ACTION_DOWN) {
			switch (v.getId()) {
			case R.id.menu_multy:
				returnIntent.putExtra("Action", 3);
				break;
			case R.id.menu_divise:
				returnIntent.putExtra("Action", 4);
				break;
			case R.id.menu_root:
				returnIntent.putExtra("Action", 6);
				break;
			case R.id.menu_minusplus:
				returnIntent.putExtra("Action", 7);
				break;
			default:
				break;
			}
		}
		setResult(RESULT_OK, returnIntent);
		finish();
		return true;
	}

	private void setViews() {
		findViewById(R.id.menu_multy).setOnTouchListener(this);
		findViewById(R.id.menu_divise).setOnTouchListener(this);
		findViewById(R.id.menu_minusplus).setOnTouchListener(this);
		findViewById(R.id.menu_root).setOnTouchListener(this);
	}

}
